<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: t_project View
	+ Description	: For record view
	+ Filename 		: v_t_project.php
 	+ creator  		: 
 	+ Created on 24/Jul/2012 10:52:52

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var t_project_DataStore;
var t_project_ColumnModel;
var t_project_ListEditorGrid;
var t_project_saveForm;
var t_project_searchForm;
var t_project_searchWindow;
var t_project_SelectedRow;
var t_project_datappn;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Data Lanjut";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (html)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

/* declare variable here for Field*/
var project_idField;
var project_codeField;
var project_typeField;
var project_nameField;
var project_shortnameField;
var project_pmField;
var project_semcmField;
var project_valueField;
var project_valueMinusPPNField;
var project_startField;
var project_p1Field;
var project_p2Field;
var m_branchField;
/* For search form */
var project_idSearchField;
var project_flagSearchField;
var project_codeSearchField;
var project_typeSearchField;
var project_nameSearchField;
var project_shortnameSearchField;
var project_pmSearchField;
var project_semcmSearchField;
var project_valueSearchField;
var project_startSearchField;
var project_p1SearchField;
var project_p2SearchField;
var m_branchSearchField;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
  	
  	/* START DATA */
	t_project_datappn = new Ext.data.Store({
		id: 't_project_datappn',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_ppn',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'setup_ppn'
		},[
			{name: 'setup_ppn', type: 'int', mapping: 'setup_ppn'}
		]),
		sortInfo:{field: 'setup_ppn', direction: "ASC"}
	});
  	t_project_datappn.load({params: {start: 0, limit: pageS}});
  	t_project_DataStore = new Ext.data.Store({
		id: 't_project_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_project&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'project_id'
		},[
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_flag', type: 'string', mapping: 'project_flag'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'project_type', type: 'string', mapping: 'project_type'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_shortname', type: 'string', mapping: 'project_shortname'},
			{name: 'project_pm', type: 'string', mapping: 'project_pm'},
			{name: 'project_semcm', type: 'string', mapping: 'project_semcm'},
			{name: 'project_value', type: 'float', mapping: 'project_value'},
			{name: 'project_value_minusppn', type: 'float', mapping: 'project_value_minusppn'},
			{name: 'project_start', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'project_start'},
			{name: 'project_start_str', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'project_start_str'},
			{name: 'project_p1', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'project_p1'},
			{name: 'project_p1_str', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'project_p1_str'},
			{name: 'project_p2', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'project_p2'},
			{name: 'project_p2_str', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'project_p2_str'},
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'div_id', type: 'int', mapping: 'div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'}
		]),
		sortInfo:{field: 'project_name', direction: "ASC"}
	});
  	t_project_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
  	
	var expander_project_list = new Ext.ux.grid.RowExpander({
        tpl : new Ext.Template(
                '<table>',
                '<tr>',
                '<td>',
                '<p><b>Kode Proyek:</b> {project_code}<br><b>Nama Proyek:</b> {project_name}</p>',
                '<p><b>Cabang:</b> {branch_name}<br><b>Singk. Proyek:</b> {project_shortname}<br>',
                '<b>Jenis Proyek:</b> {project_type}<br><b>Nama PM:</b> {project_pm}<br><b>Nama SEM/CM:</b> {project_semcm}</p>',
                '</td>',
                '<td>',
                '<p><b>NK:</b> {project_value:rpMoney}<br><b>NK - PPN:</b> {project_value_minusppn:rpMoney}',
                '<br><b>Tgl Mulai:</b> {project_start:date("l, F d, Y")}',
                '<br><b>P1:</b> {project_p1:date("l, F d, Y")}',
                '<br><b>P2:</b> {project_p2:date("l, F d, Y")}</p>',
                '</td>',
                '</tr>',
                '</table>'
            )
  	});
	
	var branchDataStore = new Ext.data.Store({
		id: 'branchDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_branch', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'branch_id'
		},[
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'branch_active', type: 'string', mapping: 'branch_active'},
			{name: 'dvo_id', type: 'int', mapping: 'dvo_id'},
			{name: 'dvo_name', type: 'string', mapping: 'dvo_name'}
		]),
		sortInfo:{field: 'branch_name', direction: "ASC"}
	});

	var divDataStore = new Ext.data.Store({
		id: 'divDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_div', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'div_id'
		},[
			{name: 'div_id', type: 'int', mapping: 'div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'}
		]),
		sortInfo:{field: 'div_name', direction: "ASC"}
	});
  	/* END DATA */
  	
  	
  	/* START FORM */
	//Form Create/Update
	project_idField= new Ext.form.NumberField({
		id: 'project_idField',
		fieldLabel: 'Project Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	project_codeField= new Ext.form.TextField({
		id: 'project_codeField',
		fieldLabel: 'Kode Proyek',
		maxLength: 10,
		anchor: '95%'
	});
	project_typeField= new Ext.form.ComboBox({
		id: 'project_typeField',
		fieldLabel: 'Jenis Proyek',
		typeAhead: true,
		triggerAction: 'all',
		store:new Ext.data.SimpleStore({
			fields:['type_value', 'type_display'],
			data: [[1,'Regular'],[2,'Join Operation']]
			}),
		mode: 'local',
		hidden : true,
       	displayField: 'type_display',
       	valueField: 'type_value',
       	lazyRender:true,
       	listClass: 'x-combo-list-small',
       	anchor: '95%'
    });
	project_nameField= new Ext.form.TextField({
		id: 'project_nameField',
		fieldLabel: 'Nama Proyek',
		maxLength: 200,
		anchor: '95%'
	});
	project_shortnameField= new Ext.form.TextField({
		id: 'project_shortnameField',
		fieldLabel: 'Singk. Proyek',
		maxLength: 30,
		anchor: '95%'
	});
	project_pmField= new Ext.form.TextField({
		id: 'project_pmField',
		fieldLabel: 'Nama PM',
		maxLength: 45,
		anchor: '95%'
	});
	project_semcmField= new Ext.form.TextField({
		id: 'project_semcmField',
		fieldLabel: 'Nama SEM/CM',
		maxLength: 45,
		anchor: '95%'
	});
	project_valueField= new Ext.ux.NumericField({
 		id: 'project_valueField',
 		fieldLabel: 'Nilai Kontrak (NK)',
		allowDecimals: true,
		thousandSeparator: '.',
		decimalPrecision: 2,
		decimalSeparator: ',',
		allowNegative: false,
		enableKeyEvents: true,
		value: 0,
		anchor: '95%',
		maxLength: 20,
		listeners : {
			'change' : function(field){
				var project_valueField_value = field.value;
				set_nkminppn(project_valueField_value);
			}
		},
		maskRe: /([0-9]+)$/
	});
	project_startField= new Ext.form.DateField({
		id: 'project_startField',
		fieldLabel: 'Tgl Mulai',
		format : 'l, F d, Y',
		anchor: '95%'
	});
	project_p1Field= new Ext.form.DateField({
		id: 'project_p1Field',
		fieldLabel: 'P1',
		format : 'l, F d, Y',
		anchor: '95%'
	});
	project_p2Field= new Ext.form.DateField({
		id: 'project_p2Field',
		fieldLabel: 'P2',
		format : 'l, F d, Y',
		anchor: '95%'
	});
	project_divField = new Ext.form.ComboBox({
		id: 'project_divField',
		fieldLabel: 'Divisi',
		store: divDataStore,
		mode: 'remote',
		displayField:'div_name',
		valueField: 'div_id',
        editable: true,
		anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	m_branchField= new Ext.form.ComboBox({
		id: 'm_branchField',
		fieldLabel: 'Cabang <font color=red>*</font>',
		store: branchDataStore,
		mode: 'remote',
		displayField:'branch_name',
		valueField: 'branch_id',
        editable: false,
		anchor: '95%',
		pageSize: 15,
		triggerAction: 'all'
	});
	var sess_comp_name = "<?php echo $project_companyNameField; //$this->session->userdata('SESSION_COMPANY_NAME');?>";
	var project_companyNameField= new Ext.form.TextField({
		id: 'project_companyNameField',
		fieldLabel: 'Nama Perusahaan',
		anchor: '95%',
		readOnly: true,
		value: sess_comp_name
	});
	project_valueMinusPPNField= new Ext.ux.NumericField({
 		id: 'project_valueMinusPPNField',
 		fieldLabel: 'Nilai Kontrak (NK)&nbsp;-&nbsp;PPN',
		allowDecimals: true,
		thousandSeparator: '.',
		decimalPrecision: 2,
		decimalSeparator: ',',
		allowNegative: false,
		enableKeyEvents: true,
		value: 0,
		anchor: '95%',
		maxLength: 20,
		readOnly : true,
		maskRe: /([0-9]+)$/
	});
	
	t_project_btn_Save=new Ext.Button({
		text: BTN_SAVE,
		handler: t_project_save
	});
	t_project_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' Project',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 700,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_t_project_save',
		layout:'form',
		items:[{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[project_idField, m_branchField, project_companyNameField, project_typeField, project_codeField, 
				       project_nameField, project_shortnameField, project_pmField, project_semcmField]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [project_valueField, project_valueMinusPPNField, project_startField, project_p1Field, project_p2Field]
			}]
		}, 
		new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED })],
		buttons: [t_project_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					t_project_reset_form();
				}
			}
		]
	});
	
	//start main grid panel
	t_project_ColumnModel = new Ext.grid.ColumnModel(
		[expander_project_list,
		{
			header: 'Project Id',
			dataIndex: 'project_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Cabang',
			dataIndex: 'branch_name',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Jenis Proyek',
			dataIndex: 'project_type',
			width: 150,
			sortable: false,
			hidden : true
		},
		{
			header: 'Kode Proyek',
			dataIndex: 'project_code',
			width: 150,
			sortable: false
		},
		{
			header: 'Nama Proyek',
			dataIndex: 'project_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Singk. Proyek',
			dataIndex: 'project_shortname',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Nama PM',
			dataIndex: 'project_pm',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Nama SEM/CM',
			dataIndex: 'project_semcm',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Nilai Kontrak (NK)',
			dataIndex: 'project_value',
			width: 150,
			align : 'right',
			sortable: false,
			renderer: function(v, params, record){
				return formatCurrency(v);
            }
		},
		{
			header: 'NK - PPN',
			dataIndex: 'project_value_minusppn',
			width: 150,
			sortable: false,
			renderer: function(v, params, record){
				return formatCurrency(v);
            },
			hidden: true
		},
		{
			header: 'Tgl Mulai',
			dataIndex: 'project_start',
			width: 150,
			sortable: false,
			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
			editor: new Ext.form.DateField({
				format: 'l, M d, Y'
			}),
			hidden: true
		},
		{
			header: 'P1',
			dataIndex: 'project_p1',
			width: 150,
			sortable: false,
			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
			editor: new Ext.form.DateField({
				format: 'l, M d, Y'
			}),
			hidden: true
		},
		{
			header: 'P2',
			dataIndex: 'project_p2',
			width: 150,
			sortable: false,
			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
			editor: new Ext.form.DateField({
				format: 'l, M d, Y'
			}),
			hidden: true
		}	]);

	t_project_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    t_project_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    t_project_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_project_confirm_update
	});

    t_project_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_project_confirm_delete
	});

	t_project_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_project_ListEditorGrid',
		el: 'fp_t_project',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: t_project_DataStore, // DataStore
		cm: t_project_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
		plugins: expander_project_list,
	  	width: 1024,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: t_project_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		t_project_gbtn_add, '-',
		t_project_gbtn_update, '-',
		t_project_gbtn_delete, /* '-',
		{
			text: BTN_SEARCH_TITLE,
			tooltip: BTN_SEARCH_TOOLTIP,
			iconCls:'icon-search',
			handler: display_form_search_window
		}, */ '-',
		new Ext.app.SearchField({
			store: t_project_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						t_project_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: t_project_reset_search,
			iconCls:'icon-refresh'
		},'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_project_export_excel
		}, '-',{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: t_project_print
		}
		]
	});
	t_project_ListEditorGrid.render();
	
	//Form Searching
	/* Identify  project_id Search Field */
	project_idSearchField= new Ext.form.NumberField({
		id: 'project_idSearchField',
		fieldLabel: 'Project Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  project_flag Search Field */
	project_flagSearchField= new Ext.form.TextField({
		id: 'project_flagSearchField',
		fieldLabel: 'Project Flag',
		maxLength: 2,
		anchor: '95%'
	});
	/* Identify  project_code Search Field */
	project_codeSearchField= new Ext.form.TextField({
		id: 'project_codeSearchField',
		fieldLabel: 'Project Code',
		maxLength: 10,
		anchor: '95%'
	});
	/* Identify  project_type Search Field */
	project_typeSearchField= new Ext.form.TextField({
		id: 'project_typeSearchField',
		fieldLabel: 'Project Type',
		maxLength: 2,
		anchor: '95%'
	});
	/* Identify  project_name Search Field */
	project_nameSearchField= new Ext.form.TextField({
		id: 'project_nameSearchField',
		fieldLabel: 'Project Name',
		maxLength: 200,
		anchor: '95%'
	});
	/* Identify  project_shortname Search Field */
	project_shortnameSearchField= new Ext.form.TextField({
		id: 'project_shortnameSearchField',
		fieldLabel: 'Project Shortname',
		maxLength: 30,
		anchor: '95%'
	});
	/* Identify  project_pm Search Field */
	project_pmSearchField= new Ext.form.TextField({
		id: 'project_pmSearchField',
		fieldLabel: 'Project Pm',
		maxLength: 45,
		anchor: '95%'
	});
	/* Identify  project_semcm Search Field */
	project_semcmSearchField= new Ext.form.TextField({
		id: 'project_semcmSearchField',
		fieldLabel: 'Project Semcm',
		maxLength: 45,
		anchor: '95%'
	});
	/* Identify  project_value Search Field */
	project_valueSearchField= new Ext.form.NumberField({
		id: 'project_valueSearchField',
		fieldLabel: 'Project Value',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  project_start Search Field */
	project_startSearchField= new Ext.form.DateField({
		id: 'project_startSearchField',
		fieldLabel: 'Project Start',
		format : 'Y-m-d'
	});
	/* Identify  project_p1 Search Field */
	project_p1SearchField= new Ext.form.DateField({
		id: 'project_p1SearchField',
		fieldLabel: 'Project P1',
		format : 'Y-m-d'
	});
	/* Identify  project_p2 Search Field */
	project_p2SearchField= new Ext.form.DateField({
		id: 'project_p2SearchField',
		fieldLabel: 'Project P2',
		format : 'Y-m-d'
	});
	/* Identify  m_branch Search Field */
	m_branchSearchField= new Ext.form.NumberField({
		id: 'm_branchSearchField',
		fieldLabel: 'M Branch Branch Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});

	/* Function for retrieve search Form Panel */
	t_project_searchForm = new Ext.FormPanel({
		labelAlign: 'left',
		layout:'form',
		bodyStyle:'padding:5px',
		autoHeight:true,
		frame: true,
		width: 500,
		items: [project_idSearchField,
				project_flagSearchField,
				project_codeSearchField,
				project_typeSearchField,
				project_nameSearchField,
				project_shortnameSearchField,
				project_pmSearchField,
				project_semcmSearchField,
				project_valueSearchField,
				project_startSearchField,
				project_p1SearchField,
				project_p2SearchField,
				m_branchSearchField
		 ],
		buttons: [{
				text: BTN_SEARCH,
				handler: t_project_list_search
			},{
				text: BTN_CANCEL,
				handler: function(){
					t_project_searchWindow.hide();
				}
			}
		]
	});
	
	t_project_searchWindow = new Ext.Window({
		title: TITLE_FORM_SEARCH+' T Project',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_t_project_search',
		items: t_project_searchForm
	});
  	
  	/* END FORM */
  	
  	
  	/* START FUNCTION */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_id');
		return 0;
	}
	
	//validation form
	function is_t_project_form_valid(){
		return (true);
	}
	
	//saving data
	function t_project_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

		if(is_t_project_form_valid()){
			var project_id_field=null;
			var project_code_field=null;
			var project_type_field=null;
			var project_name_field=null;
			var project_shortname_field=null;
			var project_pm_field=null;
			var project_semcm_field=null;
			var project_value_field=0;
			var project_value_minusppn_field=0;
			var project_start_field_date="";
			var project_p1_field_date="";
			var project_p2_field_date="";
			var m_branch_field=null;
			var project_div_field=null;

			if(project_idField.getValue()!== null){project_id_field = project_idField.getValue();}
			if(project_codeField.getValue()!== null){project_code_field = project_codeField.getValue();}
			if(project_typeField.getValue()!== null){project_type_field = project_typeField.getValue();}
			if(project_nameField.getValue()!== null){project_name_field = project_nameField.getValue();}
			if(project_shortnameField.getValue()!== null){project_shortname_field = project_shortnameField.getValue();}
			if(project_pmField.getValue()!== null){project_pm_field = project_pmField.getValue();}
			if(project_semcmField.getValue()!== null){project_semcm_field = project_semcmField.getValue();}
			if((project_valueField.getValue()!== null) && (project_valueField.getValue()!==0)){project_value_field = project_valueField.getValue();}
			if((project_valueMinusPPNField.getValue()!== null) && (project_valueMinusPPNField.getValue()!==0)){project_value_minusppn_field = project_valueMinusPPNField.getValue();}
			if(project_startField.getValue()!== ""){project_start_field_date = project_startField.getValue().format('Y-m-d');}
			if(project_p1Field.getValue()!== ""){project_p1_field_date = project_p1Field.getValue().format('Y-m-d');}
			if(project_p2Field.getValue()!== ""){project_p2_field_date = project_p2Field.getValue().format('Y-m-d');}
			if(m_branchField.getValue()!== null){m_branch_field = m_branchField.getValue();}
			if(project_divField.getValue()!== null){project_div_field = project_divField.getValue();}
			

			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_project&m=get_action',
				params: {
					project_id	: project_id_field,
					project_code	: project_code_field,
					project_type	: project_type_field,
					project_name	: project_name_field,
					project_shortname	: project_shortname_field,
					project_pm	: project_pm_field,
					project_semcm	: project_semcm_field,
					project_value	: project_value_field,
					project_value_minusppn	: project_value_minusppn_field,
					project_start	: project_start_field_date,
					project_p1	: project_p1_field_date,
					project_p2	: project_p2_field_date,
					m_branch	: m_branch_field,
					project_div: project_div_field,
					task: post2db
				},
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
							t_project_DataStore.reload();
							t_project_reset_form();
							break;
						default:
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: FAILED_SAVE,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});

		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}

		}
	}
	
	//reset form
	function t_project_reset_form(){
		project_idField.reset();
		project_idField.setValue(null);
		project_codeField.reset();
		project_codeField.setValue(null);
		project_typeField.reset();
		project_typeField.setValue(null);
		project_nameField.reset();
		project_nameField.setValue(null);
		project_shortnameField.reset();
		project_shortnameField.setValue(null);
		project_pmField.reset();
		project_pmField.setValue(null);
		project_semcmField.reset();
		project_semcmField.setValue(null);
		project_valueField.reset();
		project_valueField.setValue(null);
		project_valueMinusPPNField.reset();
		project_valueMinusPPNField.setValue(null);
		project_startField.reset();
		project_startField.setValue(null);
		project_p1Field.reset();
		project_p1Field.setValue(null);
		project_p2Field.reset();
		project_p2Field.setValue(null);
		m_branchField.reset();
		m_branchField.setValue(null);
		project_divField.reset();
		project_divField.setValue(null);
	}
	
	//set form
	function t_project_set_form(){
		project_idField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_id'));
		project_codeField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_code'));
		project_typeField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_type'));
		project_nameField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_name'));
		project_shortnameField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_shortname'));
		project_pmField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_pm'));
		project_semcmField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_semcm'));
		project_valueField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_value'));
		set_nkminppn(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_value'));
		if( t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_start_str').format('Ymd') != '19700101' && t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_start_str').format('d-m-Y') != '30-11-00-1' ){
			project_startField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_start_str'));
		}
		if( t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_p1_str').format('Ymd') != '19700101' && t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_p1_str').format('d-m-Y') != '30-11-00-1' ){
			project_p1Field.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_p1_str'));
		}
		if( t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_p2_str').format('Ymd') != '19700101' && t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_p2_str').format('d-m-Y') != '30-11-00-1' ){
			project_p2Field.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('project_p2_str'));
		}
		
		//m_branchField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('branch_id'));
		m_branchField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('branch_name'));
		project_divField.setValue(t_project_ListEditorGrid.getSelectionModel().getSelected().get('div_name'));
	}
	
	//display form to create/update
	function display_form_window(){
		post2db='CREATE';
		msg='created';
		t_project_reset_form();
	}
	
	//update main grid
	function t_project_confirm_update(){
		/* only one record is selected here */
		if(t_project_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			t_project_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	//delete main grid
	function t_project_confirm_delete(){
		// only one t_project is selected here
		if(t_project_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, t_project_delete);
		} else if(t_project_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, t_project_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	function t_project_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = t_project_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(var i = 0; i< t_project_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.project_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_project&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							t_project_DataStore.reload();
							break;
						case 3:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: 'Data ini sudah diproses tidak bisa dihapus',
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
	
	//searching data
	function t_project_list_search(){

		var project_id_search=null;
		var project_flag_search=null;
		var project_code_search=null;
		var project_type_search=null;
		var project_name_search=null;
		var project_shortname_search=null;
		var project_pm_search=null;
		var project_semcm_search=null;
		var project_value_search=null;
		var project_start_search_date="";
		var project_p1_search_date="";
		var project_p2_search_date="";
		var m_branch_search=null;

		if(project_idSearchField.getValue()!==null){project_id_search=project_idSearchField.getValue();}
		if(project_flagSearchField.getValue()!==null){project_flag_search=project_flagSearchField.getValue();}
		if(project_codeSearchField.getValue()!==null){project_code_search=project_codeSearchField.getValue();}
		if(project_typeSearchField.getValue()!==null){project_type_search=project_typeSearchField.getValue();}
		if(project_nameSearchField.getValue()!==null){project_name_search=project_nameSearchField.getValue();}
		if(project_shortnameSearchField.getValue()!==null){project_shortname_search=project_shortnameSearchField.getValue();}
		if(project_pmSearchField.getValue()!==null){project_pm_search=project_pmSearchField.getValue();}
		if(project_semcmSearchField.getValue()!==null){project_semcm_search=project_semcmSearchField.getValue();}
		if(project_valueSearchField.getValue()!==null){project_value_search=project_valueSearchField.getValue();}
		if(project_startSearchField.getValue()!==""){project_start_search_date=project_startSearchField.getValue().format('Y-m-d');}
		if(project_p1SearchField.getValue()!==""){project_p1_search_date=project_p1SearchField.getValue().format('Y-m-d');}
		if(project_p2SearchField.getValue()!==""){project_p2_search_date=project_p2SearchField.getValue().format('Y-m-d');}
		if(m_branchSearchField.getValue()!==null){m_branch_search=m_branchSearchField.getValue();}

		t_project_DataStore.baseParams = {
			task: 'SEARCH',
			project_id	:	project_id_search,
			project_flag	:	project_flag_search,
			project_code	:	project_code_search,
			project_type	:	project_type_search,
			project_name	:	project_name_search,
			project_shortname	:	project_shortname_search,
			project_pm	:	project_pm_search,
			project_semcm	:	project_semcm_search,
			project_value	:	project_value_search,
			project_start	:	project_start_search_date,
			project_p1	:	project_p1_search_date,
			project_p2	:	project_p2_search_date,
			m_branch	:	m_branch_search
		};

		t_project_DataStore.reload({params: {start: 0, limit: pageS}});
	}
	
	//reset searching
	function t_project_reset_search(){
		t_project_DataStore.baseParams = { task: 'LIST' };
		t_project_DataStore.reload({params: {start: 0, limit: pageS}});
		t_project_searchWindow.close();
	};
	
	//display form searching
	function display_form_search_window(){
		if(!t_project_searchWindow.isVisible()){
			t_project_searchWindow.show();
		} else {
			t_project_searchWindow.toFront();
		}
	}
	
	//printing
	function t_project_print(){
		var searchquery = "";
		var project_id_print=null;
		var project_flag_print=null;
		var project_code_print=null;
		var project_type_print=null;
		var project_name_print=null;
		var project_shortname_print=null;
		var project_pm_print=null;
		var project_semcm_print=null;
		var project_value_print=null;
		var project_start_print_date="";
		var project_p1_print_date="";
		var project_p2_print_date="";
		var m_branch_print=null;

		if(t_project_DataStore.baseParams.query!==null){searchquery = t_project_DataStore.baseParams.query;}
		if(t_project_DataStore.baseParams.project_id!==null){project_id_print = t_project_DataStore.baseParams.project_id;}
		if(t_project_DataStore.baseParams.project_flag!==null){project_flag_print = t_project_DataStore.baseParams.project_flag;}
		if(t_project_DataStore.baseParams.project_code!==null){project_code_print = t_project_DataStore.baseParams.project_code;}
		if(t_project_DataStore.baseParams.project_type!==null){project_type_print = t_project_DataStore.baseParams.project_type;}
		if(t_project_DataStore.baseParams.project_name!==null){project_name_print = t_project_DataStore.baseParams.project_name;}
		if(t_project_DataStore.baseParams.project_shortname!==null){project_shortname_print = t_project_DataStore.baseParams.project_shortname;}
		if(t_project_DataStore.baseParams.project_pm!==null){project_pm_print = t_project_DataStore.baseParams.project_pm;}
		if(t_project_DataStore.baseParams.project_semcm!==null){project_semcm_print = t_project_DataStore.baseParams.project_semcm;}
		if(t_project_DataStore.baseParams.project_value!==null){project_value_print = t_project_DataStore.baseParams.project_value;}
		if(t_project_DataStore.baseParams.project_start!==""){project_start_print_date = t_project_DataStore.baseParams.project_start;}
		if(t_project_DataStore.baseParams.project_p1!==""){project_p1_print_date = t_project_DataStore.baseParams.project_p1;}
		if(t_project_DataStore.baseParams.project_p2!==""){project_p2_print_date = t_project_DataStore.baseParams.project_p2;}
		if(t_project_DataStore.baseParams.m_branch!==null){m_branch_print = t_project_DataStore.baseParams.m_branch;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_project&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,
			project_id : project_id_print,
			project_flag : project_flag_print,
			project_code : project_code_print,
			project_type : project_type_print,
			project_name : project_name_print,
			project_shortname : project_shortname_print,
			project_pm : project_pm_print,
			project_semcm : project_semcm_print,
			project_value : project_value_print,
		  	project_start : project_start_print_date,
		  	project_p1 : project_p1_print_date,
		  	project_p2 : project_p2_print_date,
			m_branch : m_branch_print,
		  	currentlisting: t_project_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				window.open('./print/t_project_printlist.html','t_projectlist','height=600,width=800,resizable=1,scrollbars=0, menubar=0');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_PRINT,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	
	//exporting excel
	function t_project_export_excel(){
		var searchquery = "";
		var project_id_2excel=null;
		var project_flag_2excel=null;
		var project_code_2excel=null;
		var project_type_2excel=null;
		var project_name_2excel=null;
		var project_shortname_2excel=null;
		var project_pm_2excel=null;
		var project_semcm_2excel=null;
		var project_value_2excel=null;
		var project_start_2excel_date="";
		var project_p1_2excel_date="";
		var project_p2_2excel_date="";
		var m_branch_2excel=null;

		if(t_project_DataStore.baseParams.query!==null){searchquery = t_project_DataStore.baseParams.query;}
		if(t_project_DataStore.baseParams.project_id!==null){project_id_2excel = t_project_DataStore.baseParams.project_id;}
		if(t_project_DataStore.baseParams.project_flag!==null){project_flag_2excel = t_project_DataStore.baseParams.project_flag;}
		if(t_project_DataStore.baseParams.project_code!==null){project_code_2excel = t_project_DataStore.baseParams.project_code;}
		if(t_project_DataStore.baseParams.project_type!==null){project_type_2excel = t_project_DataStore.baseParams.project_type;}
		if(t_project_DataStore.baseParams.project_name!==null){project_name_2excel = t_project_DataStore.baseParams.project_name;}
		if(t_project_DataStore.baseParams.project_shortname!==null){project_shortname_2excel = t_project_DataStore.baseParams.project_shortname;}
		if(t_project_DataStore.baseParams.project_pm!==null){project_pm_2excel = t_project_DataStore.baseParams.project_pm;}
		if(t_project_DataStore.baseParams.project_semcm!==null){project_semcm_2excel = t_project_DataStore.baseParams.project_semcm;}
		if(t_project_DataStore.baseParams.project_value!==null){project_value_2excel = t_project_DataStore.baseParams.project_value;}
		if(t_project_DataStore.baseParams.project_start!==""){project_start_2excel_date = t_project_DataStore.baseParams.project_start;}
		if(t_project_DataStore.baseParams.project_p1!==""){project_p1_2excel_date = t_project_DataStore.baseParams.project_p1;}
		if(t_project_DataStore.baseParams.project_p2!==""){project_p2_2excel_date = t_project_DataStore.baseParams.project_p2;}
		if(t_project_DataStore.baseParams.m_branch!==null){m_branch_2excel = t_project_DataStore.baseParams.m_branch;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_project&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,
			project_id : project_id_2excel,
			project_flag : project_flag_2excel,
			project_code : project_code_2excel,
			project_type : project_type_2excel,
			project_name : project_name_2excel,
			project_shortname : project_shortname_2excel,
			project_pm : project_pm_2excel,
			project_semcm : project_semcm_2excel,
			project_value : project_value_2excel,
		  	project_start : project_start_2excel_date,
		  	project_p1 : project_p1_2excel_date,
		  	project_p2 : project_p2_2excel_date,
			m_branch : m_branch_2excel,
		  	currentlisting: t_project_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
		  		window.open('./print/t_project_printlist.xls');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_EXCEL,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	
	function set_nkminppn(value){
		var ppn_datarecord = t_project_datappn.getAt(0).data;
		var ppn = ppn_datarecord.setup_ppn;
		var ppn_nilai = value * ppn / (100 + ppn);
		var valueminppn = value - ppn_nilai;
		project_valueMinusPPNField.setValue(Math.ceil(valueminppn));
	}
  	
  	/* END FUNCTION */

	/* START CONTROL PERMISSION */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		t_project_gbtn_add.setVisible(false);
	}else{
		t_project_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		t_project_gbtn_update.setVisible(false);
	}else{
		t_project_gbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		t_project_gbtn_delete.setVisible(false);
	}else{
		t_project_gbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		t_project_btn_Save.setVisible(false);
	}else{
		t_project_btn_Save.setVisible(true);
	}
	/* END CONTROL PERMISSION */
	
});
</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_t_project_save"></div>
		<div>&nbsp;</div>
		<div id="fp_t_project"></div>
        <div id="elwindow_t_project_search"></div>
    </div>
</div>
</body>
</html>